﻿using System;
using System.Collections.Generic;
using System.Text;
using MarketSimulator.Utils.Attributes;
using MarketSimulator.Utils.Market;
using MarketSimulator.Utils.Maps;
using jade.core;
using System.Windows.Forms;
using MarketSimulator.Agents.Behaviors;

namespace MarketSimulator.Agents.Agents
{
    public class SellerAgent : Agent
    {
        public static int SellerAgentCount = 0;

        public Action<string> sellerChat;

        public Action<string> actorsChat;

        private Form TheForm;

        public override void setup()
        {
            try
            {
                object[] args = getArguments();
                TheForm = args[0] as Form;
                sellerChat = args[1] as Action<string>;
                actorsChat = args[2] as Action<string>;

                var selletNo = ++SellerAgentCount;
                var products = ProductCreator.CreateProductList();
                var city = WorldMap.Cities[(selletNo - 1) % WorldMap.Cities.Count];
                SellerAttributes sellerAttributes = new SellerAttributes(this, city, products, WriteToAgentsChat);
                sellerAttributes.RegisterAgent();

                TheForm.Invoke(sellerChat, string.Format("{0} : Location = {1} | Items = {2} ", this.getLocalName(), city.Name, sellerAttributes.GetProductInfoString()));

                //Add Behavior Section
                addBehaviour(new SellerBehavior(sellerAttributes));
            }
            catch (Exception ex)
            {
                TheForm.Invoke(sellerChat, ex.Message);
            }
            //Add Behavior Section
            //addBehaviour(new BuyerBehavior(this));
        }

        public void WriteToAgentsChat(string message)
        {
            TheForm.Invoke(actorsChat, message);
        }
    }
}
